package gov.nasa.anml.lifted;

import static gov.nasa.anml.lifted.IdentifierCode.*;
import gov.nasa.anml.PDDL;
import gov.nasa.anml.State;
import gov.nasa.anml.PDDL.FloatExpression;
import gov.nasa.anml.utility.SimpleObject;
import gov.nasa.anml.utility.SimpleString;
import gov.nasa.anml.utility.SimpleVoid;

// objects of primitive type are single-valued, unstructured, etc.
// the possibilities are 
// boolean,byte,char,short,int,long,float,double,string
//
// Don't internally distinguish string types from symbol types --
// symbols are just strings that don't need quoting to be tokenized as ids.
//
// Idea: allow quoted strings as identifiers?
// int "My var" = 2, "My Second Var" = 3;
// double quotes bad idea, but...
// int 'my var' = 2, 'my second var' = 3; 
// isn't as bad.  Could do backquotes to make _sure_ there is no
// confusion with string literals. `my var`
//
// See TypeCode

public class PrimitiveType<T> extends IdentifierImp<SimpleString,SimpleVoid> implements Type<T> {
	public TypeCode typeCode;
	public Constraint<T> constraint;

	// should be called only once per TypeCode...probably
	public PrimitiveType(TypeCode typeCode) {
		super(typeCode.name);
		this.typeCode = typeCode;
		this.constraint = null;
	}
	
	public PrimitiveType(SimpleString n, TypeCode typeCode) {
		super(n);
		this.typeCode = typeCode;
		this.constraint = null;
	}
	
	public PrimitiveType(SimpleString n, TypeCode typeCode, Constraint<T> constraint) {
		super(n);
		this.typeCode = typeCode;
		this.constraint = constraint;
	}
	
	public PrimitiveType(TypeCode typeCode, Constraint<T> constraint) {
		this.typeCode = typeCode;
		this.constraint = constraint;
	}
	
	
	public final TypeCode typeCode() {
		return typeCode;
	}

	public IdentifierCode idCode() {
		return Type;
	}

	public PrimitiveType<T> constrain(Constraint<T> c) {
		if (constraint == null || constraint.containsAll(c))
			return new PrimitiveType<T>(typeCode,c);
		return null;
	}
	
	public PrimitiveType<T> clone() {
		PrimitiveType<T> ret = null;
		try {
			ret = (PrimitiveType<T>) super.clone();
		} catch (CloneNotSupportedException e) {
			//assert false;
		}
		return ret;
	}


	// no explicit PDDL representation of non-symbolic types
	// booleans and floats are special
	public PDDL.Type asPDDLType() {
		return null;
	}
	

}
